
// WinHomeClientDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "ClientConfig.h"
#include "DownloadFile.h"
#include <map>
using namespace std;

class CWMPHost;
#include "../ServerDataHelper/ServerData.h"

	enum
	{
		PAGE_INIT,
		PAGE_SHAREFOLDER,
		PAGE_MEDIA,
		TASK_REFRESH_THUMB
	};	
	enum
	{
		DOWN_START,
		DOWN_FINISH,
		DOWN_DOTASK,
		DOWN_TASKFINISH
	};
	class tDownloadTask
	{
	public:
		tDownloadTask(tDownloadTask& Task)
		{
			m_TaskType	= Task.m_TaskType;
			m_URL		= Task.m_URL;
			m_Status	= Task.m_Status;
			m_TaskParam = Task.m_TaskParam;
		}
		tDownloadTask& operator =(const tDownloadTask& Task)
		{
			m_TaskType	= Task.m_TaskType;
			m_URL		= Task.m_URL;
			m_Status	= Task.m_Status;
			m_TaskParam = Task.m_TaskParam;
			return *this;
		}
		tDownloadTask(wstring URL,int Type)
		{
			m_TaskType = Type;
			m_URL		= URL;
			m_Status	= DOWN_START;
			m_TaskParam = NULL;
		}
		int		m_TaskType;
		wstring m_URL;
		int		m_Status;
		void*	m_TaskParam;
	};

// CWinHomeClientDlg dialog
class CWinHomeClientDlg : public CDialog,
							IDownloadNotify
{
// Construction
public:
	CWinHomeClientDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_WINHOMECLIENT_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	CString m_URL;
	afx_msg void OnBnClickedButtonPlay();

	CWMPHost* m_MediaPlayerWindow;
	DWORD m_ServerIP;
	CIPAddressCtrl m_ServerIPCtrl;
	CString m_strFilePlay;

	CClientConfig m_Config;
	afx_msg void OnBnClickedButtonRefresh();
	CListCtrl m_SharedFolderListCtrl;
	CImageList	m_RootListImageList;

	void NotifyEnd(wstring URL);


	bool IsExist(wstring strFolder);
	bool IsExistMedia(wstring strFolder);
	void RefreshServerFolders();
	wstring GetBaseURL();

	void ShowMediaFolder(wstring Folder);


	void DoTask(tDownloadTask* task);

	map<wstring,tDownloadTask*> m_Tasks;
	DownloadHelper	m_DownloadHelper;

	int			m_nPage;
	void		SetPage(int page)
	{
		m_nPage = page;
		switch(m_nPage)
		{
		case PAGE_INIT:
				m_SharedFolderListCtrl.ShowWindow(SW_SHOW);
				m_MediaListCtrl.ShowWindow(SW_HIDE);
			break;
		case PAGE_SHAREFOLDER:
			{
				m_SharedFolderListCtrl.ShowWindow(SW_SHOW);
				m_MediaListCtrl.ShowWindow(SW_HIDE);
			};
			break;
		case PAGE_MEDIA:
			{
				m_SharedFolderListCtrl.ShowWindow(SW_HIDE);
				m_MediaListCtrl.ShowWindow(SW_SHOW);
			};
			break;
		}
	};
	int			GetPage(){return m_nPage;};
	afx_msg void OnNMDblclkListServer(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnLvnItemchangedListMedia(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg LRESULT DoTaskInMessageLoop(WPARAM wParam,LPARAM lParam);
	CListCtrl m_MediaListCtrl;
	CImageList	m_MediaListImageList;

	afx_msg void OnNMDblclkListMedia(NMHDR *pNMHDR, LRESULT *pResult);

	
	void UpdateMediaThumb(SERVERDATA_MEDIA* pMedia);
};
